package com.woniuxy.pxxt.service.impl;


import com.woniuxy.pxxt.common.result.Result;
import com.woniuxy.pxxt.dao.UserTrainCourseDao;
import com.woniuxy.pxxt.dto.UserTrainCourseDto;
import com.woniuxy.pxxt.dto.train.UserTrainCourse1Dto;
import com.woniuxy.pxxt.entity.Train;
import com.woniuxy.pxxt.entity.User;
import com.woniuxy.pxxt.service.UserTrainCourseService;
import com.woniuxy.pxxt.utils.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 课程和培训中间表(TrainCourse)表服务实现类
 *
 * @author makejava
 * @since 2022-03-07 16:28:53
 */
@Service
public class UserTrainCourseServiceImpl implements UserTrainCourseService {
    @Autowired
    UserTrainCourseDao usertrainCourseDao;
    @Override
    public Result findUserTrainCourse(Integer id) {

        User user = TokenUtil.getUser();

        List<UserTrainCourseDto> userList = usertrainCourseDao.findUserTrainCourse(id,user);

//        userTrainCourse.forEach(item->{
//            usertrainCourseDao.findCourseMsg()
//        });
        for (int i = 0; i < userList.size(); i++) {
            UserTrainCourseDto courseMsg = usertrainCourseDao.
                    findCourseMsg(userList.get(i).getScoreId());

            UserTrainCourseDto userTrainCourseDto = userList.get(i);
           userTrainCourseDto.setCourseTitle(courseMsg.getCourseTitle());
            userTrainCourseDto.setCourseDes(courseMsg.getCourseDes());
            userTrainCourseDto.setCourse_grade(courseMsg.getCourse_grade());
        }

        UserTrainCourse1Dto courseDto = usertrainCourseDao.findTrainById(id);
        courseDto.setUserList(userList);

        return Result.ok(courseDto);

    }
}
